home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODUtil / Sources / FWODGeom.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.3 KB  |  271 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWODGeom.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWODGEOM_H
  13. #include "FWODGeom.h"
  14. #endif
  15.  
  16. #ifndef FWRECT_H
  17. #include "FWRect.h"
  18. #endif
  19.  
  20. // ----- OpenDoc Includes -----
  21.  
  22. #ifndef SOM_ODShape_xh
  23. #include <Shape.xh>
  24. #endif
  25.  
  26. #ifndef SOM_ODTransform_xh
  27. #include <Trnsform.xh>
  28. #endif
  29.  
  30. #ifndef SOM_ODFrame_xh
  31. #include <Frame.xh>
  32. #endif
  33.  
  34. //========================================================================================
  35. // Runtime Informations
  36. //========================================================================================
  37.  
  38. #if FW_LIB_EXPORT_PRAGMAS
  39. #pragma lib_export on
  40. #endif
  41.  
  42. #ifdef FW_BUILD_MAC
  43. #pragma segment fwodutil
  44. #endif
  45.  
  46. //========================================================================================
  47. // Globales
  48. //========================================================================================
  49.  
  50. // [HLX] We need to release them when the library is unloaded
  51. ODShape*         FW_gShapeMaker = NULL;
  52. ODTransform*     FW_gTransformMaker = NULL;
  53.  
  54. //========================================================================================
  55. // Globales Methods
  56. //========================================================================================
  57.  
  58. //----------------------------------------------------------------------------------------
  59. //    ::PrivCreateShapeTransformMaker
  60. //----------------------------------------------------------------------------------------
  61.  
  62. FW_FUNC_ATTR void FW_PrivCreateShapeTransformMaker(Environment *ev, ODFrame* odFrame)
  63. {
  64.     if (FW_gShapeMaker == NULL)
  65.     {
  66.         FW_gShapeMaker = odFrame->CreateShape(ev);
  67.         
  68.         FW_gShapeMaker->SetRectangle(ev, (ODRect*) &FW_kZeroRect);
  69.     }
  70.         
  71.     if (FW_gTransformMaker == NULL)
  72.         FW_gTransformMaker = odFrame->CreateTransform(ev);
  73. }
  74.  
  75. //----------------------------------------------------------------------------------------
  76. // FW_NewODShape
  77. //----------------------------------------------------------------------------------------
  78.  
  79. FW_FUNC_ATTR ODShape* FW_NewODShape_Empty(Environment* ev)
  80. {
  81.     FW_ASSERT(FW_gShapeMaker != NULL);
  82.     return FW_gShapeMaker->NewShape(ev);
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. //    ::FW_NewODShape
  87. //----------------------------------------------------------------------------------------
  88.  
  89. FW_FUNC_ATTR ODShape* FW_NewODShape_PlatformRect(Environment *ev, const FW_SPlatformRect& rect)
  90. {
  91.     return FW_NewODShape(ev, FW_CRect(rect));
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    ::FW_NewODShape
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_FUNC_ATTR ODShape* FW_NewODShape_Rect(Environment *ev, const FW_CRect& rect)
  99. {
  100.     ODShape *odShape  =  NULL;
  101.     FW_VOLATILE(odShape);
  102.     
  103.     FW_TRY
  104.     {
  105.         odShape = ::FW_NewODShape(ev);
  106.         odShape->SetRectangle(ev, (ODRect*) &rect);    
  107.     }
  108.     FW_CATCH_BEGIN
  109.     FW_CATCH_EVERYTHING()
  110.     {
  111.         
  112.         if (odShape!=NULL)
  113.             odShape->Release(ev);
  114.             
  115.         FW_THROW_SAME();
  116.     }
  117.     FW_CATCH_END
  118.     
  119.     return odShape;
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    ::FW_NewODShape
  124. //----------------------------------------------------------------------------------------
  125.  
  126. FW_FUNC_ATTR ODShape* FW_NewODShape_Region(Environment *ev, ODRgnHandle rgnHandleToAdopt)
  127. {
  128.     ODShape *odShape  =  NULL;
  129.     FW_VOLATILE(odShape);
  130.     
  131.     FW_TRY
  132.     {
  133.         odShape = ::FW_NewODShape(ev);
  134.         FW_SetShapeRegion(ev, odShape, rgnHandleToAdopt);
  135.     }
  136.     FW_CATCH_BEGIN
  137.     FW_CATCH_EVERYTHING()
  138.     {    
  139.         if (odShape!=NULL)
  140.             odShape->Release(ev);
  141.             
  142.         FW_THROW_SAME();
  143.     }
  144.     FW_CATCH_END
  145.     
  146.     return odShape;
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. //    ::FW_NewODShape
  151. //----------------------------------------------------------------------------------------
  152.  
  153. FW_FUNC_ATTR ODShape* FW_NewODShape_Shape(Environment *ev, ODShape* otherShape)
  154. {
  155.     return otherShape->Copy(ev);
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. // FW_NewODTransform
  160. //----------------------------------------------------------------------------------------
  161.  
  162. FW_FUNC_ATTR ODTransform* FW_NewODTransform_Empty(Environment* ev)
  163. {
  164.     FW_ASSERT(FW_gTransformMaker != NULL);
  165.     return FW_gTransformMaker->NewTransform(ev);
  166. }
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    ::FW_NewODTransform
  170. //----------------------------------------------------------------------------------------
  171.  
  172. FW_FUNC_ATTR ODTransform* FW_NewODTransform_Transform(Environment *ev, ODTransform* otherTransform)
  173. {
  174.     return otherTransform->Copy(ev);
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. //    ::FW_NewODTransform
  179. //----------------------------------------------------------------------------------------
  180.  
  181. FW_FUNC_ATTR ODTransform* FW_NewODTransform_Point(Environment *ev, const FW_CPoint& offset)
  182. {
  183.     ODTransform *odTransform  =  NULL;
  184.     FW_VOLATILE(odTransform);
  185.     
  186.     FW_TRY
  187.     {
  188.         odTransform = ::FW_NewODTransform(ev);
  189.         odTransform->MoveBy(ev, (ODPoint*)&offset);
  190.     }
  191.     FW_CATCH_BEGIN
  192.     FW_CATCH_EVERYTHING()
  193.     {    
  194.         if (odTransform)
  195.             odTransform->Release(ev);
  196.             
  197.         FW_THROW_SAME();
  198.     }
  199.     FW_CATCH_END
  200.     
  201.     return odTransform;
  202. }
  203.  
  204. //----------------------------------------------------------------------------------------
  205. //    ::FW_NewODTransform
  206. //----------------------------------------------------------------------------------------
  207.  
  208. FW_FUNC_ATTR ODTransform* FW_NewODTransform_Point2(Environment *ev, const FW_CPoint& offset, const FW_CPoint& scale)
  209. {
  210.     ODTransform *odTransform  =  NULL;
  211.     FW_VOLATILE(odTransform);
  212.     
  213.     FW_TRY
  214.     {
  215.         odTransform = ::FW_NewODTransform(ev);
  216.         odTransform->ScaleBy(ev, (ODPoint*)&scale);
  217.         odTransform->MoveBy(ev, (ODPoint*)&offset);
  218.     }
  219.     FW_CATCH_BEGIN
  220.     FW_CATCH_EVERYTHING()
  221.     {    
  222.         if (odTransform)
  223.             odTransform->Release(ev);
  224.             
  225.         FW_THROW_SAME();
  226.     }
  227.     FW_CATCH_END
  228.     
  229.     return odTransform;
  230. }
  231.  
  232. //----------------------------------------------------------------------------------------
  233. //    FW_GetShapeRegion
  234. //----------------------------------------------------------------------------------------
  235.  
  236. FW_FUNC_ATTR ODRgnHandle FW_GetShapeRegion(Environment *ev, ODShape* odShape)
  237. {
  238. #ifdef FW_BUILD_MAC
  239.     return odShape->GetQDRegion(ev);
  240. #endif
  241. #ifdef FW_BUILD_WIN
  242.     return odShape->GetWinRegion(ev);
  243. #endif
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    FW_SetShapeRegion
  248. //----------------------------------------------------------------------------------------
  249.  
  250. FW_FUNC_ATTR void FW_SetShapeRegion(Environment *ev, ODShape* odShape, ODRgnHandle rgnHandle)
  251. {
  252. #ifdef FW_BUILD_MAC
  253.     odShape->SetQDRegion(ev, rgnHandle);
  254. #endif
  255. #ifdef FW_BUILD_WIN
  256.     odShape->SetWinRegion(ev, rgnHandle);
  257. #endif
  258. }
  259.  
  260.  
  261. //----------------------------------------------------------------------------------------
  262. //    FW_GetShapeBoundingBox
  263. //----------------------------------------------------------------------------------------
  264.  
  265. FW_FUNC_ATTR FW_CRect FW_GetShapeBoundingBox(Environment *ev, ODShape* odShape)
  266. {
  267.     ODRect rect;
  268.     odShape->GetBoundingBox(ev, &rect);
  269.     return rect;
  270. }
  271.